local luoyong = fk.CreateSkill {
  name = "lvshi__luoyong",
}

Fk:loadTranslationTable {
  ["lvshi__luoyong"] = "洛涌",
  [":lvshi__luoyong"] = "出牌阶段，你可将一张牌置于牌堆底，然后重铸任意张黑色手牌。若无牌可重铸，你调整手牌至上限并结束出牌阶段。",
  ["#lvshi__luoyong-prompt"] = "置底一张牌，重铸任意张黑色手牌",
  ["#ls__luoyong-recast"] = "你可以重铸任意张黑色手牌",

  ["$lvshi__luoyong1"] = "洛水起涟漪，粉彩点绛唇。",
  ["$lvshi__luoyong2"] = "洛水汤汤过，白裳掩玉容。",

}

luoyong:addEffect("active", {
  anim_type = "control",
  card_num = 1,
  target_num = 0,
  prompt = "#lvshi__luoyong-prompt",
  can_use = function(self, player)
    return not player:isNude()
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    if #effect.cards > 0 then
      room:moveCards({
        from = player.id,
        ids = effect.cards,
        toArea = Card.DrawPile,
        moveReason = fk.ReasonPut,
        skillName = luoyong.name,
        proposer = player.id,
        drawPilePosition = -1,
      })
    end
    if player.dead then return end
    local ids = table.filter(player:getCardIds("h"), function (id)
      return Fk:getCardById(id).color == Card.Black
    end)
    if #ids == 0 then
      local x = player:getHandcardNum() - player:getMaxCards()
      if x > 0 then
        room:askToDiscard(player, {
          min_num = x,
          max_num = x,
          include_equip = false,
          skill_name = luoyong.name,
          cancelable = false}
        )
      elseif x < 0 then
        player:drawCards(-x, self.name)
      end
      player:endPlayPhase()
    else
      local cids = room:askToCards(player, {
        min_num = 1,
        max_num = #ids,
        include_equip = false,
        skill_name = luoyong.name,
        cancelable = true, 
        pattern = tostring(Exppattern{ id = ids }),
        prompt = "#ls__luoyong-recast"
      })
      if #cids > 0 then
        room:recastCard(cids, player, self.name)
      end
    end
  end,
})

return luoyong